from certificate_manager.models import User, UserManager, Department
from json import loads

def init_user():
    # 删除除管理员以外的用户
    User.objects.exclude(is_staff=True).delete()
    with open('教师信息表.json') as f:
        user_list = loads(f.read())

    dep = Department.objects.get(name='教师')
    for (i, user) in enumerate(user_list):
        User.objects.create_user(uid=user['uid'], password=user['uid'], name=user['name'], department=dep)
        if(i % 10 == 0):
            print(f'Importing -- {i}/{len(user_list)}')

